package com.weipai.springboot.module.dao.impl;

import com.weipai.springboot.model.IntegralGoods;
import com.weipai.springboot.model.SpecialGoods;
import com.weipai.springboot.module.dao.SpecialGoodsDao;
import com.weipai.springboot.module.mapper.SpecialGoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author songmengqiang
 * @create 2018-08-28 18:27
 **/
@Repository
public class SpecialGoodsDaoImpl implements SpecialGoodsDao {

    @Autowired
    private SpecialGoodsMapper specialGoodsMapper;

    @Override
    public int insertSpecialGoods(SpecialGoods specialGoods) {
        return specialGoodsMapper.insert(specialGoods);
    }

    @Override
    public int updateSpecialGoods(SpecialGoods specialGoods) {
        return specialGoodsMapper.updateByPrimaryKeySelective(specialGoods);
    }

    @Override
    public int deleteSpecialGoods(Integer id) {
        return specialGoodsMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int batchDeleteSpecialGoods(Integer[] ids) {
        int sum = 0;
        for (int i = 0; i < ids.length; i++) {
            sum += specialGoodsMapper.deleteByPrimaryKey(ids[i]);
        }
        return sum;
    }

    @Override
    public List<Map<String, Object>> listSpecialGoods(String specialOfferId, Integer page, Integer size) {
        return specialGoodsMapper.listSpecialGoods(specialOfferId, (page - 1) * size, size);
    }

    @Override
    public int specialGoodsCount(String specialOfferId) {
        return specialGoodsMapper.specialGoodsCount(specialOfferId);
    }

    //通过会场id和商品id确定该商品是否添加入了会场
    @Override
    public IntegralGoods selectByGoodsId(String goodsId, String specialOfferId) {
        return specialGoodsMapper.selectByGoodsId(goodsId, specialOfferId);
    }

    @Override
    public SpecialGoods selectByGoodsIdAndspecialId(String goodsId, String specialOfferId) {
        return specialGoodsMapper.selectByGoodsIdAndspecialId(goodsId,specialOfferId);
    }
}
